package com.jason.library.expand

object ExpandFunctionMain {

    @JvmStatic
    fun main(args:Array<String>) {
        var company = Company()
        company.employee()
        company.expandEmployee()
        println("company code = ${company.code}")
        println("before company name = ${company.name}")
        company.name = "云+社区2222";
        println("after company name = ${company.title}")
    }
}


class Company {

    var code = 100

    fun employee() {
        println("My company has 100 employee")
    }


    var title : String = ""
        get() = field
        // 设置属性值（age）时，先执行（field相关）
        set(value) {
            if (value.length < 0) {
                field = ""
            } else {
                field = value
            }
        }
}

/**
 * 作为Company类 的 扩展函数
 */
fun Company.expandEmployee() {
    println("The company expand employee!")
}

/**
 * 作为Company类 的 扩展属性
 */
var Company.name : String
    get() = "云+社区"
    set(value)  {
        title = value

    }
